home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / VCW411.ZIP / SQUARE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  2.1 KB  |  125 lines

  1. // -[Keep_Heading]-
  2.  
  3.  
  4. // -[Copyright_Mesg]-
  5. // --------------------------------------------------------------- //
  6. // (c) Copyright 1993-1994. Step Ahead Software Pty Limited. All rights reserved.
  7. // Class Source Filename: SQUARE.cpp
  8. // Description: 
  9. // Implements a square object. Uses the Rectangle function.
  10. // --------------------------------------------------------------- //
  11.  
  12.  
  13. #include "SQUARE.h"
  14.  
  15.  
  16. // -[Keep_cpp_Extras]-
  17.  
  18.  
  19. // -[Module_Function_Decs]-
  20.  
  21.  
  22. // -[Module_Data_Decs_Def]-
  23.  
  24.  
  25. // -[Global_Data_Defs]-
  26.  
  27.  
  28. // -[Static_Member_Data_Defs]-
  29.  
  30.  
  31. // -[Function_Defs]-
  32.  
  33. // Returns a hash value
  34. hashValueType
  35. Square::hashValue() const
  36. {
  37.   return 0;
  38. }
  39.  
  40. // Tests Equality
  41. int
  42. Square::isEqual(const Object& testObject) const
  43. {
  44.   return FALSE;
  45. }
  46.  
  47. // Unique class ID
  48. classType
  49. Square::isA() const
  50. {
  51.   return SquareClass;
  52. }
  53.  
  54. void
  55. Square::write(Ropstream os)
  56. {
  57.   // Call to base class write functions
  58.   os << SideLength;
  59. }
  60.  
  61. Pvoid
  62. Square::read(Ripstream is)
  63. {
  64.   // Call to base class read functions
  65.   is >> SideLength;
  66.   return this;
  67. }
  68.  
  69. // Constructs the object before a stream input operation
  70. Square::Square(StreamableInit s)
  71.     : Shape(s)
  72. {
  73. }
  74.  
  75. // Output Class Info
  76. void
  77. Square::printOn(Rostream outputStream) const
  78. {
  79. }
  80.  
  81. // Class Name
  82. char *
  83. Square::nameOf() const
  84. {
  85.   return "Square";
  86. }
  87.  
  88. // Constructs the square object with the given side length.
  89. Square::Square(int InitX, int InitY, int InitSide)
  90. : Shape(InitX, InitY)
  91. {
  92.     Width = Height = SideLength = InitSide;
  93.     Colour = RGB(255, 255, 0); 
  94. }
  95.  
  96. // Draws the square using the GDI function "Rectangle".
  97. void
  98. Square::Show(HDC hDC)
  99. {
  100.     HBRUSH hBrush = CreateSolidBrush(Colour);
  101.     HBRUSH hOldBrush;
  102.  
  103.     hOldBrush = SelectObject(hDC, hBrush);
  104.  
  105.     // Draw the square
  106.     Rectangle(hDC, X, Y, X + SideLength, Y + SideLength);
  107.  
  108.     SelectObject(hDC, hOldBrush);
  109.     DeleteObject(hBrush);
  110. }
  111.  
  112. // -[Persistent]-
  113. // OWL 1.0 streamability
  114. PTStreamable Square::build()
  115. {
  116.   return new Square(streamableInit);
  117. }
  118.  
  119. const Pchar Square::streamableName() const
  120. {
  121.   return "Square";
  122. }
  123.  
  124. TStreamableClass RegSquare("Square", Square::build,
  125.   __DELTA(Square));